from 节点与引用实现二叉树 import BinaryTree


# 前序遍历 根左右
def preorder(tree: BinaryTree):
    if tree:
        print(tree.get_root_value())
        preorder(tree.get_left_child())
        preorder(tree.get_right_child())


# 后序遍历 左右根
def postorder(tree: BinaryTree):
    if tree is not None:
        postorder(tree.get_left_child())
        postorder(tree.get_right_child())
        print(tree.get_root_value())


# 中序遍历  左根右
def inorder(tree: BinaryTree):
    if tree is not None:
        inorder(tree.get_left_child())
        print(tree.get_root_value())
        inorder(tree.get_right_child())


if __name__ == '__main__':
    tree = BinaryTree(2)
    tree.insert_left(3)
    tree.insert_left(1)
    tree.insert_right(4)
    preorder(tree)
